<?php
require_once 'core/PluginLoader.php';
require_once 'core/PluginModel.php';

$pluginDir = __DIR__ . '/plugins';
$loader = new PluginLoader($pluginDir);
$pluginModel = new PluginModel();

echo "开始同步插件到数据库...\n";

// 获取文件系统中的所有插件
$filePlugins = $loader->getAllPlugins();
echo "发现 " . count($filePlugins) . " 个插件文件\n";

$successCount = 0;
$errorCount = 0;

foreach ($filePlugins as $plugin) {
    try {
        // 同步插件信息到数据库
        $result = $pluginModel->syncPlugin($plugin);
        if ($result) {
            echo "✓ 同步成功: " . $plugin['title'] . "\n";
            $successCount++;
        } else {
            echo "✗ 同步失败: " . $plugin['title'] . "\n";
            $errorCount++;
        }
    } catch (Exception $e) {
        echo "✗ 同步错误: " . $plugin['title'] . " - " . $e->getMessage() . "\n";
        $errorCount++;
    }
}

echo "\n同步完成！\n";
echo "成功: $successCount 个\n";
echo "失败: $errorCount 个\n";

// 显示数据库中的插件统计
$stats = $pluginModel->getStats();
echo "\n数据库统计:\n";
echo "总插件数: " . $stats['total_plugins'] . "\n";
echo "活跃插件数: " . $stats['active_plugins'] . "\n";
echo "总浏览量: " . $stats['total_views'] . "\n";
echo "总点赞数: " . $stats['total_likes'] . "\n";

echo "\n现在可以访问网站查看插件列表了！\n";
?> 